package com.wnxy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wnxy.entity.User;
import com.wnxy.mapper.UserMapper;
import com.wnxy.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    /**
     * 模拟CPU占用过高
     * @return
     */
    @Override
    public String testQuery() {
        boolean flag = true;
        while (flag){

        }
        return "CPU占用过高";
    }

    @Override
    public String testDealData() {
        // 模拟死锁
        Object o1 = new Object();
        Object o2 = new Object();

        new Thread(()->{
            synchronized (o1) {
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (o2) {
                    System.out.println(Thread.currentThread().getName()+":执行");
                }
            }
        },"线程1").start();

        new Thread(()->{
            synchronized (o2) {
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (o1) {
                    System.out.println(Thread.currentThread().getName()+":执行");
                }
            }
        },"线程2").start();

        return "出现死锁问题";
    }
}
